package com.jaws.demo.common.exception;

import com.jaws.core.common.vo.OpResponse;
import com.jaws.core.mvc.exception.ApplicationException;
import com.jaws.core.mvc.exception.IErrors;

/**
 * API 前置的异常码划分为:
 *
 * @author maojian
 * <p>
 * 300000~300999
 * @date 2017-05-10 17:53:03
 * @since v1.0.0
 */
public enum ClientDemoExceptionCode implements IErrors<OpResponse> {

	HYSTRIX_ERROR(310000,"断路器错误模拟"),
	CACHE_ERROR(310001, "cache错误"),
	SYS_ERROR(300999, "系统错误"),;


	private int code;
	private String desc;

	private ClientDemoExceptionCode(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public int getCode() {
		return code;
	}

	public String getDesc() {
		return desc;
	}


	public OpResponse parse() {
		OpResponse result = new OpResponse();
		result.setCode(code);
		result.setDisplay(desc);
		return result;
	}

	@Override
	public OpResponse parse(Object... args) {
		OpResponse result = new OpResponse();
		result.setCode(code);
		String formatReason = String.format(desc, args);
		result.setDisplay(formatReason);
		return result;
	}

	@Override
	public OpResponse parseMsg(String message, Object... args) {
		this.desc = message;
		return parse(args);
	}

	@Override
	public ClientDemoException exp() {
		return new ClientDemoException(code, desc);
	}

	@Override
	public ClientDemoException exp(Object... args) {
		String formatReason = String.format(desc, args);
		return new ClientDemoException(code, formatReason);
	}

	@Override
	public ClientDemoException expMsg(String message, Object... args) {
		String formatReason = String.format(message, args);
		return new ClientDemoException(code, formatReason);
	}

	@Override
	public ApplicationException exp(Throwable arg0, Object... arg1) {
		return null;
	}

	@Override
	public ApplicationException expMsg(String arg0, Throwable arg1, Object... arg2) {
		return null;
	}


}
